"use strict";
cc._RF.push(module, '648d9QrXgpAkoV6lH8rhWxC', 'levelAvoidEnemy');
// scripts/modes/normalMode/levelAvoid/base/levelAvoidEnemy.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnemyMoveType = void 0;
var data_control_1 = require("../../../../engines/libs/data_control");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var levelAvoidEnemy = /** @class */ (function (_super) {
    __extends(levelAvoidEnemy, _super);
    function levelAvoidEnemy() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.scaleLabFontSize = 40;
        _this.player = null;
        _this.moveData = null;
        _this.levelbase = null;
        _this.isMove = false;
        _this.time = 0;
        _this.lab = null;
        _this.targetIndex = 0;
        _this.targetPos = null;
        _this.berziTime = null;
        _this.startBorn = false;
        _this.isBreath = false;
        _this.initScale = null;
        _this.scaleWay = 1;
        _this.targetCall = null;
        _this._scale = 1;
        return _this;
    }
    levelAvoidEnemy_1 = levelAvoidEnemy;
    levelAvoidEnemy.prototype.onLoad = function () {
        this.lab = this.node.getChildByName("lab").getComponent(cc.Label);
    };
    levelAvoidEnemy.prototype.update = function (dt) {
        if (!this.moveData)
            return;
        if (!this.isMove)
            return;
        if (!this.startBorn)
            return;
        if (this.levelbase.isPause)
            return;
        if (this.levelbase.openTips)
            return;
        // this.time += dt;
        // if (this.time < 0.016) return;
        // this.time = 0;
        this.breath();
        switch (this.moveData.moveType) {
            case EnemyMoveType.one:
                var pos = this.node.getPosition().add(this.player.node.getPosition().sub(this.node.getPosition()).normalize().mul(this.moveData.moveSpeed * dt / 0.016));
                this.node.setPosition(pos);
                break;
            case EnemyMoveType.two:
                var postwo = this.node.getPosition().add(this.moveData.moveDirection.mul(this.moveData.moveSpeed * dt / 0.016));
                this.node.setPosition(postwo);
                break;
            case EnemyMoveType.three:
                var mag = this.player.node.getPosition();
                if (Math.abs(mag.y - this.moveData.startPos.y) < this.moveData.attRanglePos.y && Math.abs(mag.x - this.moveData.startPos.x) < this.moveData.attRanglePos.x && !this.player.isDeathIng) {
                    var pos_1 = this.node.getPosition().add(this.player.node.getPosition().sub(this.node.getPosition()).normalize().mul(this.moveData.moveSpeed * dt / 0.016));
                    this.node.setPosition(pos_1);
                }
                else {
                    var startPosMag = this.moveData.startPos.sub(this.node.getPosition());
                    var pos_2 = this.node.getPosition().add(startPosMag.normalize().mul(this.moveData.moveSpeed * dt / 0.016));
                    if (startPosMag.mag() < this.moveData.moveSpeed * dt / 0.016)
                        pos_2 = this.moveData.startPos;
                    this.node.setPosition(pos_2);
                }
                break;
            case EnemyMoveType.four:
                if (this.moveData.targetPos[this.targetIndex] == null)
                    break;
                var targetMag = this.moveData.targetPos[this.targetIndex].sub(this.node.getPosition());
                var targetpos = this.node.getPosition().add(targetMag.normalize().mul(this.moveData.moveSpeed * dt / 0.016));
                if (targetMag.mag() < this.moveData.moveSpeed * dt / 0.016) {
                    targetpos = this.moveData.targetPos[this.targetIndex];
                    this.targetIndex++;
                    if (this.targetIndex >= this.moveData.targetPos.length) {
                        this.targetCall && this.targetCall();
                        // this.targetCall = null;
                        this.targetIndex = 0;
                        break;
                    }
                }
                // console.error(this.node.y,targetpos.x,targetpos.y)
                this.node.setPosition(targetpos);
                break;
            case EnemyMoveType.five:
                if (this.targetPos == null) {
                    this.targetPos = cc.v2(data_control_1.default.getRandNumberOfArrayTwo([this.moveData.rangleV4.x, this.moveData.rangleV4.y]), data_control_1.default.getRandNumberOfArrayTwo([this.moveData.rangleV4.z, this.moveData.rangleV4.w]));
                }
                var fivetargetMag = this.targetPos.sub(this.node.getPosition());
                var fivetargetpos = this.node.getPosition().add(fivetargetMag.normalize().mul(this.moveData.moveSpeed));
                if (fivetargetMag.mag() < this.moveData.moveSpeed) {
                    // fivetargetpos = this.targetPos
                    this.targetPos = cc.v2(data_control_1.default.getRandNumberOfArrayTwo([this.moveData.rangleV4.x, this.moveData.rangleV4.y]), data_control_1.default.getRandNumberOfArrayTwo([this.moveData.rangleV4.z, this.moveData.rangleV4.w]));
                }
                this.node.setPosition(fivetargetpos);
                break;
            case EnemyMoveType.six:
                if (this.berziTime == null)
                    this.berziTime = dt;
                else
                    this.berziTime += dt;
                var targetPos = null;
                if (this.berziTime > this.moveData.beiziTime)
                    targetPos = this.moveData.routePosList[this.moveData.routePosList.length - 1];
                else {
                    targetPos = data_control_1.default.getBerziPos(this.moveData.routePosList, this.berziTime / this.moveData.beiziTime);
                }
                this.node.setPosition(targetPos);
                break;
        }
    };
    levelAvoidEnemy.prototype.init = function (showlab, player, moveData, levelbase, scaleNum, needBornAni) {
        var _this = this;
        if (scaleNum === void 0) { scaleNum = 1; }
        if (needBornAni === void 0) { needBornAni = true; }
        showlab && (this.lab.string = showlab);
        this.levelbase = levelbase;
        this.player = player;
        this.moveData = moveData;
        if (moveData.startPos)
            this.node.setPosition(moveData.startPos);
        // this.scheduleOnce(() => {
        //     this.node.width = this.lab.node.width;
        //     this.node.height = this.lab.node.height;
        //     this.node.getComponent(cc.BoxCollider).size.width = this.node.width
        //     this.node.getComponent(cc.BoxCollider).size.height = this.node.height
        // })
        if (needBornAni) {
            this.scale = 0;
            cc.tween(this.node.getComponent(levelAvoidEnemy_1))
                .to(0.3, { scale: scaleNum })
                .call(function () {
                _this.startBorn = true;
            })
                .start();
            // this.levelbase.scheduleAny(() => {
            //     this.scale += scaleNum / 0.3;
            // })
        }
        else {
            this.scale = scaleNum;
            this.startBorn = true;
            this.scheduleOnce(function () {
                _this.node.width = _this.lab.node.width;
                _this.node.height = _this.lab.node.height;
                _this.node.getComponent(cc.BoxCollider).size.width = _this.node.width - 40;
                _this.node.getComponent(cc.BoxCollider).size.height = _this.node.height - 40;
            });
        }
        this.initScale = scaleNum;
    };
    levelAvoidEnemy.prototype.startAvoid = function (move) {
        if (move === void 0) { move = true; }
        this.isMove = move;
    };
    levelAvoidEnemy.prototype.changeMoveData = function (moveData) {
        this.moveData = moveData;
    };
    levelAvoidEnemy.prototype.setBreath = function () {
        this.isBreath = true;
        // this.breath()
    };
    levelAvoidEnemy.prototype.breath = function () {
        if (!this.isBreath)
            return;
        var minScale = 0.7 * this.initScale;
        var maxScale = 1.3 * this.initScale;
        // this.player.levelbase.scheduleAny(() => {
        if (!this.isBreath)
            return;
        if (this.scale > maxScale) {
            this.scaleWay = -1;
        }
        else if (this.scale < minScale) {
            this.scaleWay = 1;
        }
        this.scale += this.scaleWay * cc.director.getDeltaTime() / 1;
        // })
    };
    levelAvoidEnemy.prototype.setTargetCallBack = function (call, isDelCall) {
        var _this = this;
        if (isDelCall === void 0) { isDelCall = true; }
        this.targetCall = function () {
            call && call();
            if (isDelCall)
                _this.targetCall = null;
        };
    };
    Object.defineProperty(levelAvoidEnemy.prototype, "scale", {
        get: function () {
            return this._scale;
        },
        set: function (v) {
            var _this = this;
            this._scale = v;
            this.lab.fontSize = (this._scale * this.scaleLabFontSize) || 1;
            this.lab.lineHeight = (this._scale * this.scaleLabFontSize) || 1;
            this.scheduleOnce(function () {
                _this.node.width = _this.lab.node.width;
                _this.node.height = _this.lab.node.height;
                _this.node.getComponent(cc.BoxCollider).size.width = _this.node.width - 20;
                _this.node.getComponent(cc.BoxCollider).size.height = _this.node.height - 20;
            });
        },
        enumerable: false,
        configurable: true
    });
    var levelAvoidEnemy_1;
    __decorate([
        property({ displayName: "一倍大小下字体大小" })
    ], levelAvoidEnemy.prototype, "scaleLabFontSize", void 0);
    levelAvoidEnemy = levelAvoidEnemy_1 = __decorate([
        ccclass
    ], levelAvoidEnemy);
    return levelAvoidEnemy;
}(cc.Component));
exports.default = levelAvoidEnemy;
var EnemyMoveType;
(function (EnemyMoveType) {
    /**直线追踪 */
    EnemyMoveType[EnemyMoveType["one"] = 0] = "one";
    /**直行 */
    EnemyMoveType[EnemyMoveType["two"] = 1] = "two";
    /**范围追踪 */
    EnemyMoveType[EnemyMoveType["three"] = 2] = "three";
    /**目标到达 */
    EnemyMoveType[EnemyMoveType["four"] = 3] = "four";
    /**范围内移动 */
    EnemyMoveType[EnemyMoveType["five"] = 4] = "five";
    /**贝塞尔曲线 */
    EnemyMoveType[EnemyMoveType["six"] = 5] = "six";
})(EnemyMoveType = exports.EnemyMoveType || (exports.EnemyMoveType = {}));

cc._RF.pop();